﻿function getViewportHeight() {
  var h = 0;

  if (self.innerHeight)
    h = window.innerHeight;
  else if (document.documentElement && document.documentElement.clientHeight)
    h = document.documentElement.clientHeight;
  else if (document.body)
    h = document.body.clientHeight;

  return h;
}

function windowResize() {
  $("#divdata").css("height", getViewportHeight() - 72);
}

function showName(receivename) {
  var name;
  jQuery.ajax({
    type: "POST",
    url: "Services/AlarmList.ashx?method=getReceivename",
    data: { "name": receivename },
    async: false,
    cache: false,
    dataType: "text",
    success: function(resp) {
      name = resp;
    },
    error: function(request, textStatus, errorThrown) {

      alert("获取数据失败");
    }
  });
  return name;
};

function showSingleName(UserID) {
  var name;
  jQuery.ajax({
    type: "POST",
    url: "Services/AlarmList.ashx?method=getSingleName",
    data: { "name": UserID },
    async: false,
    cache: false,
    dataType: "text",
    success: function(resp) {
      name = resp;
    },
    error: function(request, textStatus, errorThrown) {

      alert("获取数据失败");
    }
  });
  return name;
};

jQuery().ready(function() {
//    $('#tool').click(function () {

//        var mode = $('#tool').attr('mode');
//        if (mode == 'up') {
//            $('#tbsearch').slideUp(1000, function () {
//                $('#tool').attr('mode', 'down');
//                $('#tool').removeClass("up").addClass("down");

//            });
//        }
//        else {
//            $('#tbsearch').slideDown(1000,
//     function () {
//         $('#tool').attr('mode', 'up');
//         //$('#tool').css('background-image',"url('../../images/up.gif')");
//         $('#tool').removeClass("down").addClass("up");

//     });
//        }

//    });
  function CurentTime() {
    var now = new Date();

    var year = now.getFullYear(); //年
    var month = now.getMonth() + 1; //月
    var day = now.getDate(); //日

    var hh = now.getHours(); //时
    var mm = now.getMinutes(); //分
    var ss = now.getSeconds(); //秒
    var clock = year + "-";

    if (month < 10)
      clock += "0";

    clock += month + "-";

    if (day < 10)
      clock += "0";

    clock += day + " ";

    if (hh < 10)
      clock += "0";

    clock += hh + ":";
    if (mm < 10) clock += "0";
    clock += mm + ":";

    if (ss < 10)
      clock += "0";
    clock += ss;
    return (clock);
  };

  function formatDate(date, style) {
    var y = date.getFullYear();
    var M = (date.getMonth() + 1).toString();
    if (M.length == 1) {
      M = "0" + M;
    }
    var d = (date.getDate()).toString();
    if (d.length == 1) {
      d = "0" + d;
    }
    var h = (date.getHours()).toString();
    if (h.length == 1) {
      h = "0" + h;
    }
    var m = (date.getMinutes()).toString();
    if (m.length == 1) {
      m = "0" + m;
    }
    var s = (date.getSeconds()).toString();
    if (s.length == 1) {
      s = "0" + s;
    }
    return style.replace("yyyy", y).replace("MM", M).replace("dd", d).replace("hh", h).replace("mm", m).replace("ss", s);
  }


});

function openDialogResize(actionUrl, width, height) {
  var locX = (screen.width - width) / 2;
  var locY = (screen.height - height) / 2;
  var attrs = null;
//            attrs = "status:no;directories:yes;scroll:yes;Resizable=yes;";
//            attrs += " Width:" + width ;
//            attrs += " Height:" + height ;
//            attrs += " Left:" + locX ;
//            attrs += " Top:" + locY ;
  //return window.showModalDialog(actionUrl, self, attrs);
  attrs = "width=" + width;
  attrs += ",height=" + height;
  attrs += ",left=" + locX;
  attrs += ",top=" + locY;
  attrs += ",toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,status=no";
  window.open(actionUrl, "新窗体", attrs);
};

//获取url传参
// indow.location.href  转向页面    如 test.aspx?id=1
// indow.location.search  页面传递数据，如 ?id=1
function getParameter(param) {
  var query = window.location.search;
  var iLen = param.length;
  var iStart = query.indexOf(param);
  if (iStart == -1)
    return "";
  iStart += iLen + 1;
  var iEnd = query.indexOf("&", iStart);
  if (iEnd == -1)
    return query.substring(iStart);

  return query.substring(iStart, iEnd);
};

function myajax(url, para) {
  var result;
  jQuery.ajax({
    type: "POST",
    url: url,
    data: para,
    async: false,
    cache: false,
    dataType: "json",
    success: function(resp) {
      //   console.log(resp);
      result = resp;

    },
    error: function(request, textStatus, errorThrown) {
      alert("加载错误");
    }
  });
  return result;
};

function myajaxhtml(url, para, datatype) {
  var result;
  jQuery.ajax({
    type: "POST",
    url: url,
    data: para,
    async: false,
    cache: false,
    dataType: datatype,
    success: function(resp) {
      //   console.log(resp);
      result = resp;

    },
    error: function(request, textStatus, errorThrown) {
      alert("加载错误");
    }
  });
  return result;
};

function convertdate_y_M_d(value) {
  var date = new Date(parseInt(value.replace("/Date(", "").replace(")/", ""), 10));
  var y = date.getFullYear();
  var M = (date.getMonth() + 1).toString();
  if (M.length == 1) {
    M = "0" + M;
  }
  var d = (date.getDate()).toString();
  if (d.length == 1) {
    d = "0" + d;
  }

  return y + "-" + M + "-" + d;
};

String.prototype.trim = function() {
  return this.replace(/^\s\s*/, "").replace(/\s\s*$/, "");
};